package wifiunion.com.notice;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

//import com.wifiunion.intelligencegate.place.PlaceInfoListActivity;

/**
 * Created by Administrator on 2016/12/20.
 */

public class BaseActivity extends AppCompatActivity {

    private BroadcastReceiver mBr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        mBr = new BroadcastReceiver() {
//            @Override
//            public void onReceive(Context context, Intent intent) {
//                if (com.wifiunion.intelligencegate.utils.Constants.LOGOUT_ACTION.equals(intent.getAction())) {
//
//                    String erromsg = intent.getStringExtra("errormsg");
//                    Toast.makeText(context, erromsg, Toast.LENGTH_SHORT).show();

//                    SharedPreferencesUtils.setUserSharedPreferences(null, context);
//                    SharedPreferencesUtils.setSharedPreferences(Constants.CONFIG_AUTHTOKEN, "", context);
//                    SharedPreferencesUtils.setSharedPreferences(Constants.CONFIG_PWD, "", context);
//                    if (!(BaseActivity.this instanceof PlaceInfoListActivity)) {
//                        Intent it = new Intent(BaseActivity.this, PlaceInfoListActivity.class);
//                        it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
//                        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                        startActivity(it);
//                        finish();
//                    } else {
//                        //login登录页登录失败，身份不正确的时候关掉加载进度
//                        ((PlaceInfoListActivity) (BaseActivity.this)).hiddenProgress();
//                    }

//                }
//            }
//        };
//        registerReceiver(mBr, new IntentFilter(com.wifiunion.intelligencegate.utils.Constants.LOGOUT_ACTION));
        try {
            ((BaseApplication) getApplication()).addActivity(this);
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mBr != null) {
            unregisterReceiver(mBr);
            mBr = null;
        }

        try {
            ((BaseApplication) getApplication()).removeActivity(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }

}
